#include "cpu_info.h"
#include <fcntl.h>      //open close
#include <unistd.h>     //read
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdint.h>
#include "file_handle.h"

#define CPU_ZEMP_FILE   "/sys/class/thermal/thermal_zone0/temp"
#define TEMP_LEN        10

//温度
char cput_temp[TEMP_LEN];

char cpu_time[9];
char cpu_date[11];


char* cpu_get_temp(void) {
    int fd = 0; //文件描述符
    int ret = 0;
    fd = open(CPU_ZEMP_FILE, O_RDONLY);
    if (fd == -1)
    {
        return NULL;
    }

    ret = read(fd, cput_temp, TEMP_LEN);

    if (ret == -1) {
        return NULL;
    }

    close(fd);

    return cput_temp;
}

char* cpu_get_time(void) {
    time_t t = time(NULL);
    struct tm* tm = localtime(&t);
    strftime(cpu_time, sizeof(cpu_time), "%H:%M:%S", tm);
    return cpu_time;
}
char* cpu_get_date(void) {
    time_t t = time(NULL);
    struct tm* tm = localtime(&t);
    strftime(cpu_date, sizeof(cpu_date), "%Y-%m-%d", tm);
    return cpu_date;
}

#define PROC_CPUINFO "/proc/cpuinfo"
uint8_t cpu_get_num(void) {
    char content[1000];
    file_read(PROC_CPUINFO, content, 1000);
    printf("%s\n", content);
    return 0;
}


#define PROC_STAT "/proc/stat"




